package cn.daniellee.plugin.pl;

import cn.daniellee.plugin.pl.listener.PortalListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.java.JavaPlugin;

public class PortalLimiter extends JavaPlugin {

	private static PortalLimiter instance;

	private String prefix;

	private String[] allTypeArray;

	private boolean netherTopProtect;

	private int maxSize;

	public void onEnable(){
		instance = this;

		loadConfig();
		getLogger().info(" ");
		getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> PortalLimiter Loaded <<<<<<<<<<<<<<<<<<<<<<<<");
		getLogger().info(">>>>> If you encounter any bugs, please contact author's QQ: 768318841 <<<<<");
		getLogger().info(" ");

		//加载全部类型为字符串数组
		EntityType[] entityTypes =  EntityType.values();
		allTypeArray = new String[entityTypes.length];
		for (int i = 0; i < entityTypes.length; i++) {
			allTypeArray[i] = entityTypes[i].toString();
		}

		Bukkit.getPluginManager().registerEvents(new PortalListener(), this);
		Bukkit.getPluginCommand("portallimiter").setExecutor(this);
	}

	public void loadConfig() {
		getLogger().info("[PortalLimiter] Loading config...");
		prefix = "&7[&b" + getConfig().getString("prompt-prefix", "PortalLimiter") + "&7] &3: &r";
		netherTopProtect = getConfig().getBoolean("nether-top-protect", true);
		maxSize = getConfig().getInt("max-size", 0);
		if(!getDataFolder().exists()) getDataFolder().mkdirs();
		saveDefaultConfig();
	}

	@Override
	public void onDisable() {
		getLogger().info(" ");
		getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> PortalLimiter Unloaded <<<<<<<<<<<<<<<<<<<<<<<<");
		getLogger().info(" ");
	}

	public static PortalLimiter getInstance() {
		return instance;
	}

	public String getPrefix() {
		return prefix;
	}

	public String[] getAllTypeArray() {
		return allTypeArray;
	}

	public boolean isNetherTopProtect() {
		return netherTopProtect;
	}

	public int getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(int maxSize) {
		this.maxSize = maxSize;
	}
}